<template>
    <div>
        <!-- 1.定义model数据form，在script的数据data库里return这个form
        2.status-icon是表单校验的时候的图标
        3.el-form表单是有校验功能的，需要添加:rules，定义传入的属性也叫rules
        4.通过ref来获取form的实例，方便调用form下面的属性和方法
         -->
        <el-form  :model="form" status-icon :rules="rules" ref="form" label-width="100px" class="login-container"> 
            <h3 class="login-title">用户登录</h3>
            <el-form-item label="用户名" label-width="80px" prop="username" class="username">
                <el-input type="input" v-model="form.username" autocomplete="off" placeholder="请输入账号"></el-input>
            </el-form-item>
            <el-form-item label="密码" label-width="80px" prop="password">
                <el-input type="password" v-model="form.password" autocomplete="off" placeholder="请输入密码"></el-input>
            </el-form-item>
            <el-form-item class="login_submit">
                <el-button type="primary" @click="login" class="login_submit" >登录</el-button>
                <!-- <router-link class="to-Main" to="/">
                    <el-button type="primary" @click="login" class="login_submit" >登录</el-button>
                </router-link> -->
            </el-form-item>
        </el-form>
    </div>
</template>

<style lang="less" scoped>
.login-container {
    border-radius: 15px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background-color: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
}
.login-title {
    margin: 0px auto 40px auto;
    text-align: center;
    color: #505458;
}
.login_submit{
    margin: 10px auto 0 auto;
}
</style>

<script>
export default{
    name: 'vueLogin',
    data() {
        return {
            form:{
            },
            rules: {   //进行表单校验的定义
            username: [
                {
                    required: true,
                    message: "请输入用户名",
                    trigger: "blur"  //触发的方式blur
                },
                {
                    min: 3,   //对用户名称长度的限制，最小为3
                    message:"用户名长度不能小于3位",
                    trigger: "blur"
                }
            ],
            password: [
                 {
                    required: true,
                    message: "请输入密码",
                    trigger: "blur"  //触发的方式blur
                },
            ]
            }
        }
    },
    methods: {
        login(){
            // if(this.username === 'admin' && this.password ==='123'){
            //           this.$router.push('/')  //登录成功就跳转到首页
            //       }else{
            //           alert("用户名或密码错误！"); //登录失败
            //       }
        }
    }
}
</script>
